<?php
/**
 * Created by PhpStorm.
 * User: waw
 * Date: 2019/6/19
 * Time: 22:51
 */
header("Content-Type:application/json;charset=utf-8");
if(isset($_REQUEST["good_id"])){
    $idnum=$_REQUEST["good_id"];
    //根据good_id获取产品数据

    //获取数据  转为数组
    $dataStr=removeBOM(file_get_contents("./data/good.json"));
    $dataArr=json_decode($dataStr);
    for($i=0;$i<count($dataArr);$i++){
        if ($dataArr[$i]->good_id==$idnum){print_r(json_encode(($dataArr[$i])));
            break;}
    }


}else{
    //没有id就把所有数据都显示出去
    print_r(file_get_contents("./data/good.json"));
}
function removeBOM($data) {    
    if (0 === strpos(bin2hex($data), 'efbbbf')) {        
        return substr($data, 3);    
    }    
    return $data;
}
